package html5environment;

import java.net.URI;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;

import customplugin.projects.CustomProjectSupport;

public class NewWizard1 extends Wizard implements INewWizard, IExecutableExtension {
	private WizardNewProjectCreationPage _pageOne;
	private PageOne _pageTwo;
	private IConfigurationElement _configurationElement;
	private IWorkbench _workbench;
	private IStructuredSelection _selection;
	 

	public NewWizard1() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		// TODO Auto-generated method stub
		 setWindowTitle("Creating HTML5 App for Dymora");
		 _workbench = workbench;
		 _selection = selection;

	}
	
	@Override
	 public void addPages() {
	 super.addPages();
	 
     _pageOne = new WizardNewProjectCreationPage("Dymora App Wizard"); 
	 _pageOne.setTitle("Dymora App");
	 _pageOne.setDescription("Creating HTML5 App for Dymora");
	 _pageTwo = new PageOne(); 
	 
	 addPage(_pageOne);
	 addPage(_pageTwo);
	 }

	@Override
	public boolean performFinish() {
		 String name = _pageOne.getProjectName();
		 String applicationId = _pageTwo.getApplicationId().getText();
		 String groupId = _pageTwo.getGroupId().getText();
		 String titles = _pageTwo.getTitles().getText();
		 String api = _pageTwo.getScapi().getText();
		 String build = _pageTwo.getBuild().getText();
		 String version = _pageTwo.getVersion().getText(); 
		 String url = _pageTwo.getUrl().getText(); 
		    URI location = null;
		    if (!_pageOne.useDefaults()) {
		        location = _pageOne.getLocationURI();
		    } // else location == null
		   
		    
		    
		    CustomProjectSupport.createProject(name, location, applicationId, api, groupId, titles, build, version, url);
		  
		return true;
	}

	@Override
	public void setInitializationData(IConfigurationElement config,
			String propertyName, Object data) throws CoreException {
		// TODO Auto-generated method stub
		 _configurationElement = config;
		
	}

}
